﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.Library;
using IHISCETeim.BLL;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UFXOC55NSLAdd : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
                
            }
        }

        protected virtual void addmenu()
        {
            addmenu("55NSL");
            
        }

        protected  void addmenu(string MachineType)
        { 
             string X=  CompleteCheckXMLHelper.GetGZQRXMLStr();
             UFXCompletingCheckInfo obj = Request.SerializableObject<UFXCompletingCheckInfo>();

             //OCompletingCheckInfo checkobj=OCompletingCheckController.GetBySerialNumber(obj.SerialNumber);
             //if (checkobj != null)
             //{
             //    ErrorJson("机号" + obj.SerialNumber+"已添加过，无需再添加");
             //    return;
             //}

             if (obj.SerialNumber.Length <= 5)
             {
                 ErrorJson("机号" + obj.SerialNumber + "不对，请重新输入");
                 return;
             }

             obj.QDQDJItem = CompleteCheckXMLHelper.GetQTJDJXMLStr();
             obj.XNJCItem = CompleteCheckXMLHelper.GetXRJCXMLStr();
             obj.GZQRItem = CompleteCheckXMLHelper.GetGZQRXMLStr();
             obj.MachineType = MachineType;
             obj.CreateDate = DateTime.Now;
             
             string[] TypeS = GetRequestValue<string>("Type", "").Split(new char[] { ',' });            
             string[] WTS = GetRequestValue<string>("WT", "").Split(new char[] { ',' });
             string[] YYFXS = GetRequestValue<string>("YYFX", "").Split(new char[] { ',' });
             string[] JGS = GetRequestValue<string>("JG", "").Split(new char[] { ',' });
             string[] OKS = GetRequestValue<string>("OK", "").Split(new char[] { ',' });
             string[] QRS = GetRequestValue<string>("QR", "").Split(new char[] { ',' });
            List<UFXCompletingCheckNGInfo> ngitems = new List<UFXCompletingCheckNGInfo>();

             for (int index = 0; index < TypeS.Count(); index++)
             {
                UFXCompletingCheckNGInfo ngitem = new UFXCompletingCheckNGInfo();
                 if (!string.IsNullOrEmpty(TypeS[index]))
                 {
                    ngitem.Type = TypeS[index];
                    ngitem.WT = WTS[index];
                    ngitem.YYFX = YYFXS[index];
                    ngitem.JG = JGS[index];
                    ngitem.OK = OKS[index];
                    ngitem.QR = QRS[index];
                    ngitems.Add(ngitem);
                 }
             }
            //
            //obj.CheckDate=
            // this.AddLog(Permission.新增,null,obj);
             if (UFXCompletingCheckController.Add(obj, ngitems))
                 SuccessJson("添加成功", "");
             else
                 ErrorJson("添加失败,相应机号已存在，不能重复添加");
        }

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }

        protected override string DWZRef
        {
            get { return "UFXCompletingCheckList"; }
        }


        protected string GetNGSelect(string controlName)
        {
            string selectHtml = "";//;"<select name=\"NG_铁履H前10m\"><option value=\"OK\" selected>OK</option><option value="NG->OK">NG->OK</option><option value="NG">NG</option></select>";
            string[] ngItme=new string[]{"NG","NG->OK","OK"};
            foreach(string item in ngItme)
            {
                selectHtml+=string.Format("<option value=\"{0}\" {1}>{0}</option>",item,item=="OK"?"selected":"");
            }
            return string.Format("<select name=\"NG_{1}\">{0}</select>", selectHtml, controlName);
        }
    }
}